package com.huitian.net.utils;

import java.text.SimpleDateFormat
import java.time.{Instant, ZoneId, ZonedDateTime}
import java.util.concurrent.TimeUnit

object TimeUtils {
  def getTimeStamp(time: String): Long = {
    val newtime: Long = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ).parse( time ).getTime / 1000
    newtime
  }

  def getTime(time: Long): String = {
    val newtime :String = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(time*1000)
    println(newtime)
    newtime
  }

  def getTimeParse(time: BigInt): String = {
    val timeStamp = time.toLong
    val secondsPortion = TimeUnit.NANOSECONDS.toSeconds(timeStamp)
    val nanosPortion  = timeStamp % 1000000000L;
    val instant: Instant = Instant.ofEpochSecond(secondsPortion, nanosPortion);


    return instant.toString
  }
  def getTimeHour(time: BigInt): Int = {
    val timeStamp = time.toLong
    val secondsPortion = TimeUnit.NANOSECONDS.toSeconds(timeStamp)
    val nanosPortion  = timeStamp % 1000000000L;
    val instant: Instant = Instant.ofEpochSecond(secondsPortion, nanosPortion);
    val z  = ZoneId.of("Asia/Shanghai");
    val zdt: ZonedDateTime = instant.atZone(z);

    val hour: Int = zdt.getHour
    hour
  }
}
